/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.stm.common;

import com.stm.db.Customer;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 *
 * @author wooriaviva
 */
public class DBConnection {
    private static String DB_DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
    private static String DB_URL = "jdbc:sqlserver://10.239.195.228:1433;databaseName=STOCKHOLDER;User=fin;Password=1234";

    public static void connectTest() {
        
        
        Connection con = null;//SqlConnection
        Statement stmt = null;//SqlCommand
        ResultSet rs = null;// IDataReader

        try {
            Class.forName(DB_DRIVER);
            con = DriverManager.getConnection(DB_URL);
            // Create and execute an SQL statement that returns some data.
            String SQL = "SELECT TOP 10 * FROM customer";
            Customer cot = new Customer();
            
            stmt = con.createStatement();
            rs = stmt.executeQuery(SQL);
            // Iterate through the data in the result set and display it.
            
            while (rs.next()) {
            //Retrive 4 and 6 column value:
                System.out.println(rs.getString(4) + " " + rs.getString(6));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            if (rs != null) {
                try {
                    rs.close();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            if (con != null) {
                try {
                    con.close();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
    }
}
